# @Time : 2025-01-17 10:23
# @Author : Fioman 
# @Phone : 13149920693
"""
算法的一些配置,用到的一些参数就是幻数放到这里来
"""
from enum import Enum

showState = False
thresUsedTotalboard = 35  # 物料区域识别阈值
filterArea = 5000  # 物料区域查找的时候的面积阈值

colorWhite = (255, 255, 255)
colorGreen = (0, 255, 0)
colorBlue = ( 0, 0,255)
colorRed = (255, 0, 0)
colorPink = (147, 20, 255)
colorList = [colorRed, colorGreen, colorBlue]
calcThresBig = 20  # 识别偏大阈值
calcThresSmall = 15  # 识别偏小阈值
jointLineExtend = 15
angleMax = 20  # 允许的偏转角度,识别的第一边,相对于物料区域


class CheckErrorFlag(Enum):
    Small = "识别尺寸偏小"
    Big = "识别尺寸偏大"
    OverLap = "叠板"
    MidError = "中缝太靠近底部"
    Default = "默认错误"


class CutlineResult():
    """
    切割线结果
    """

    def __init__(self):
        self.state = False
        self.info = ""
        self.imgRes = None  # 返回的结果图像
        self.robotX01: float = 0.0  # 机器人01 X坐标
        self.robotY01: float = 0.0  # 机器人01 Y坐标
        self.robotR01: float = 0.0  # 机器人01 角度
        self.robotX02: float = 0.0  # 机器人02 X坐标
        self.robotY02: float = 0.0  # 机器人02 Y坐标
        self.robotR02: float = 0.0  # 机器人02 角度
        self.cutLen: float = 0.0  # 切割后长度(平行于治具)
        self.cutWidth: float = 0.0  # 切割宽度(垂直于治具   )
        self.isFirstCut: bool = False  # 是否是第一刀
        self.isSecondCut: bool = False  # 是否是第二刀
        self.isThirdCut: bool = False  # 是否是第三刀
        self.isFourthCut: bool = False  # 是否是第四刀
        self.calcWidth: float = 0.0  # 识别尺寸宽度
        self.calcHeight: float = 0.0  # 识别尺寸高度

    def pack_info(self):
        """
        封装识别消息
        :return:
        """
        self.info = (f"机器人01坐标: {self.robotX01}, {self.robotY01},角度: {self.robotR01},"
                     f"机器人02坐标: {self.robotX02}, {self.robotY02},角度: {self.robotR02},"
                     f"切割后板长(宽度): {self.cutLen},切割后板宽(高度): {self.cutWidth},"
                     f"是否是第一刀: {self.isFirstCut},是否是第二刀: {self.isSecondCut},"
                     f"是否是第三刀: {self.isThirdCut},是否是第四刀: {self.isFourthCut}")


class CheckResult():
    def __init__(self):
        self.state = False
        self.errorFlag = CheckErrorFlag.Default
        self.box = None
        self.info = ""
        self.calcSize = (0, 0)
        self.calcError = (0, 0)


class TotalboardResult:

    def __init__(self):
        self.state = False
        self.totalboardGray = None  # 返回旋转之后的totalboard的结果,灰度图结果
        self.totalboardColor = None  # 返回的旋转后的totalboardRes的结果,带框框的结果
        self.totalboardOffset = 0
        self.boxMaster = (0, 0,), (0, 0), 0  # 中心 宽高 和 角度
        self.totalboardThres = None  # 就是阈值分割后的那个结果
        self.rectPoints = None
        self.info = ""
